package com.core.model.lxf;

import com.core.dto.GoodDTO;
import com.core.model.AbstractEntity;
import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-7-22
 * Time: 下午11:26
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "good")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Good extends AbstractEntity {

    private String name;
    private String age;
    @ManyToOne
    @JoinColumn(name = "good_type_id")
    private GoodType goodType;
    @Column(columnDefinition = "int unsigned")
    private long ip;

    public Good() {
    }

    public Good(String name, String age) {
        this.name = name;
        this.age = age;
    }

    public Good(String name, String age, GoodType goodType, long ip) {
        this.name = name;
        this.age = age;
        this.goodType = goodType;
        this.ip = ip;
    }

    public void update(GoodDTO goodDTO) {
        this.name = goodDTO.getName();
        this.age = goodDTO.getAge();
    }

    public String name() {
        return name;
    }

    public String age() {
        return age;
    }

    public GoodType goodType() {
        return goodType;
    }

    public long ip() {
        return ip;
    }

    public void setIp(long ip) {
        this.ip = ip;
    }
}
